from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta



def today_yyyymmdd():
    today = datetime.now()
    return today.strftime('%Y%m%d')

def yesterday_yyyymmdd():
    today = datetime.now()
    yesterday = today - timedelta(days=1)
    yesterday_str = yesterday.strftime('%Y%m%d')
    return yesterday_str

def before_n_years_yyyymmdd(n):
    today = datetime.now()
    the_day = today - relativedelta(years=n)
    the_day_str = the_day.strftime('%Y%m%d')
    return the_day_str

def before_3y_yyyymmdd():
    today = datetime.now()
    the_day = today - relativedelta(years=3)
    the_day_str = the_day.strftime('%Y%m%d')
    return the_day_str


def before_2y_yyyymmdd():
    today = datetime.now()
    the_day = today - relativedelta(years=2)
    the_day_str = the_day.strftime('%Y%m%d')
    return the_day_str


def before_1y_yyyymmdd():
    today = datetime.now()
    the_day = today - relativedelta(years=1)
    the_day_str = the_day.strftime('%Y%m%d')
    return the_day_str


def before_6m_yyyymmdd():
    today = datetime.now()
    the_day = today - relativedelta(months=6)
    the_day_str = the_day.strftime('%Y%m%d')
    return the_day_str

def before_3m_yyyymmdd():
    today = datetime.now()
    the_day = today - relativedelta(months=3)
    the_day_str = the_day.strftime('%Y%m%d')
    return the_day_str


def before_1m_yyyymmdd():
    today = datetime.now()
    the_day = today - relativedelta(months=1)
    the_day_str = the_day.strftime('%Y%m%d')
    return the_day_str


def before_2w_yyyymmdd():
    today = datetime.now()
    the_day = today - relativedelta(weeks=2)
    the_day_str = the_day.strftime('%Y%m%d')
    return the_day_str


def before_1w_yyyymmdd():
    today = datetime.now()
    the_day = today - relativedelta(weeks=1)
    the_day_str = the_day.strftime('%Y%m%d')
    return the_day_str


def workday_of_range(sd_yyyymmdd, ed_yyyymmdd):
    sd = datetime.strptime(sd_yyyymmdd, '%Y%m%d').date()
    ed = datetime.strptime(ed_yyyymmdd, '%Y%m%d').date()

    workday_cnt = 0
    current_date = sd

    while current_date <= ed:
        if current_date.weekday() < 5:
            workday_cnt += 1
        current_date += timedelta(days=1)
    return workday_cnt

def y_m_d_to_ymd(date_str):
    date_obj = datetime.strptime(date_str, '%Y-%m-%d')
    return date_obj.strftime('%Y%m%d')

def y_m_d_to_date(date_str):
    date_obj = datetime.strptime(date_str, '%Y-%m-%d')
    return date_obj.date()

if __name__ == '__main__':
    d = y_m_d_to_date("2025-09-10")
    print(d)